/**
 * Created by Ahmed Medhat & Sweelam on 9/12/2014.
 */

    /* Create obj that hold container.
       Set the svg container and make its attributes as default
    */
    var Bound_region = {

    width: 800,
    height: 800,
	SVG: function(){
	     var Container = d3.select("body")
                        .append("svg")
                        .attr("width", this.width)
                        .attr("height", this.height);

                return Container;
		 },

    /* Default start/end points */
        x_start: 500,
        y_start: 500,
        x_max: 500,
        y_max: 500,
        x_scale: function(){
            d3.scale.identity().domain([this.y_start, this.x_max]);
        },

        y_scale: function(){
            d3.scale.identity().domain([this.y_start, this.y_max]);
        },

        xAxis : function(axis_position){
            d3.svg.axis()
                .scale(Bound_region.x_scale())
                .orient(axis_position);
        }

		};

/* The object that holds all geometry primitives */
    var Geo_Primitives = {

        Draw_xAxis: function(){
           d3.select("svg").append('g')
                .call(Bound_region.xAxis('bottom'))

        },

        // Line draw function.
        DrawLine : function(x1, y1, x2, y2,stroke,stroke_width)
        {
            /* Default Var*/
            x1           = x1||0;
            y1           = y1||0;
            x2           = x2||0;
            y2           = y2||0;
            stroke       =stroke||"black";
            stroke_width =stroke_width||1;

            /* Shape D3 Drawer*/
            d3.select("svg").append("line")
                .attr("x1", x1)
                .attr("y1", y1)
                .attr("x2", x2)
                .attr("y2", y2)
                .attr("stroke",stroke)
                .attr("stroke-width",stroke_width);
        },

        // Rectangle draw function.
        DrawRect: function(x, y, width, height,rx, ry ,fill,stroke,stroke_width,fill_opacity)
        {

            /* Default Var*/
            x             = x||0;
            y             = y||0;
            rx            =rx||0;
            ry            =ry||0;
            width         =width||5;
            height        =height||5;
            stroke        =stroke||"red";
            stroke_width  =stroke_width||1
            fill          =fill || "black";
            fill_opacity       =fill_opacity || 1;

            /* Shape D3 Drawer*/
            d3.select("svg").append("rect")
                .attr("x", x)
                .attr("y", y)
                .attr("width", width )
                .attr("height", height )
                .attr("fill", fill)
                .attr("rx",rx)
                .attr("ry",ry)
                .attr("stroke",stroke)
                .attr("stroke-width",stroke_width)
                .attr("fill-opacity",fill_opacity);
        },

        // Circle draw function.
        DrawCircle: function(cx,cy,r,stroke,stroke_width,fill)
        {
            /* Default Var*/
            cx           =cx||0;
            cy           =cy||0;
            r            =r||2;
            stroke       =stroke||"red";
            stroke_width =stroke_width||1
            fill         =fill || "black";

            /* Shape D3 Drawer*/
            d3.select("svg").append("circle")
                .attr("cx" ,cx)
                .attr("cy" ,cy)
                .attr("r" ,r)
                .attr("stroke",stroke)
                .attr("stroke-width",stroke_width)
                .attr("fill",fill);
        },

        // Ellipse draw function.
        DrawEllipse: function(cx, cy, rx, ry,fill)
        {
            /* Default Var*/
            cx           =cx||0;
            cy           =cy||0;
            rx            =ry||100;
            ry            =ry||10;
            fill         =fill || "black";

            /* Shape D3 Drawer*/
            d3.select("svg").append("ellipse")
                .attr("cx", cx)
                .attr("cy", cy)
                .attr("rx", rx)
                .attr("ry", ry)
                .attr("fill", fill)
        },

        // Polygon draw function.
        DrawPolygon: function(points,fill,stroke,stroke_width,fill_rule)
        {

            /* Default Var*/
            points           =points||"100,10 40,198 100,10 40,198 100,10 40,198";
            fill         =fill || "black";
            stroke         =stroke || "black";
            stroke_width         =stroke_width || 1;
            fill_rule         =fill_rule || "nonzero";

            /* Shape D3 Drawer*/
            d3.select("svg").append("polygon")
                .attr("points",points)
                .attr("fill",fill)
                .attr("stroke",stroke)
                .attr("stroke-width",stroke_width)
                .attr("fill-rule",fill_rule);
        },

        // Polyline draw function.
        DrawPolyline: function(points,fill,stroke,stroke_width)
        {

            /* Default Var*/
            points           =points||"100,10 40,198 100,10 40,198 100,10 40,198";
            fill         =fill || "white";
            stroke         =stroke || "black";
            stroke_width         =stroke_width || 1;


            /* Shape D3 Drawer*/
            d3.select("svg").append("polyline")
                .attr("points",points)
                .attr("fill",fill)
                .attr("stroke",stroke)
                .attr("stroke-width",stroke_width);

        }
};

